package com.xys.auth.controller;

import com.xys.auth.bean.Permission;
import com.xys.auth.service.IPermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
@RequestMapping("/permission")
public class permissionController {

    @Autowired
    IPermissionService permissionService;

    @RequestMapping("/findAll.do")
    public ModelAndView findAll(){
        ModelAndView modelAndView = new ModelAndView();

        modelAndView.setViewName("permission-list");

        List<Permission> permissions = permissionService.findAll();

        modelAndView.addObject("permissionList",permissions);

        return modelAndView;
    }

    @RequestMapping("/save.do")
    public String save(Permission permission){

        permissionService.save(permission);

        return "redirect:findAll.do";
    }


    @RequestMapping("/findById")
    public ModelAndView findById(String id){
        Permission permission=permissionService.findById(id);
        ModelAndView modelAndView=new ModelAndView();
        modelAndView.setViewName("permission-show");
        modelAndView.addObject("permission",permission);
        return modelAndView;
    }
    
    @RequestMapping("/deletePermission.do")
    public String deletePermission(String id){
        permissionService.deletePermission(id);
        return "redirect:findAll.do";
    }
}
